/*
 * CKernel.h
 *
 *  Created on: 29.11.2011
 *      Author: Kirill Blinov
 *      Copyright: LGPL
 */

#ifndef CKERNEL_H_
#define CKERNEL_H_

#include <string.h>
#include "Manager Resource/CGameWorld.h"
#include "CSceneVisualisationProxy.h"
#include "Logic/IGameLogic.h"
#include "../Visualisator/Camera.h"
#include "../TThreadSafeQueue.h"

class CKernel
{
private:
	SCREEN_DIMENSION 		  dimension;
	bool             		  mainLoopControl;
	CGameWorld*      		  currentGameWorld;
	CSceneVisualisationProxy* visualisationProxy;
	CGameCamera               mainCamera; //Default parameters are suitable
	IGameLogic*               gameLogic;

	TThreadSafeQueue<INPUT_MESSAGE*>  *inputMessageQueue;
	TThreadSafeQueue<UI_MESSAGE*>     *uiMessageQueue;

	static CKernel* Kernel;

private:
	static const UINT INPUT_MESSAGE_QUEUE_SIZE = 30;

private:
	static const UINT RENDER_FPS = 30;
	static const UINT CICLE_DURATION_THREASHOLD_PERCENT = 5;

private:
	CKernel();
	virtual ~CKernel();

	void KernelMainLoop();
	bool ProcessInputMessage( const INPUT_MESSAGE* InputMessage );

public:
	static CKernel* GetInstance()
	{
		if ( NULL == Kernel )
		{
			Kernel = new CKernel();
		}
		return Kernel;
	}

	static void DeleteInstance()
	{
		if ( NULL != Kernel )
		{
			delete Kernel;
			Kernel = NULL;
		}
	}

	bool InitEngine( const std::string GuiTemplate,
					 const std::string GuiMap,
					 const std::string EffectsConfig,
					 const std::string UnitsConfig,
					 const std::string WorldConfig,
					 const SCREEN_DIMENSION &Window );

	bool LoadWorld( const std::string WorldConfig );

	void RunEngine();

	void KillEngine();
};

#endif /* CKERNEL_H_ */
